import java.awt.Image;


/**
 * @author  8100556811
 */
public class Sprite {

	/**
	 * @uml.property  name="anim"
	 * @uml.associationEnd  
	 */
	private Animation anim;
	//positios pixels
	/**
	 * @uml.property  name="x"
	 */
	private float x;
	/**
	 * @uml.property  name="y"
	 */
	private float y;
	//velocity
	private float dx;
	private float dy;
	
	//creates a new sprite object with the animation
	
	public Sprite(Animation anim)
	{
		this.anim = anim;
		
	}
	
	/*
	 * updates this sprite's animation and its position based on the velocity
	 */
	
	public void update(long elapsedTime)
	{
		x+=dx* elapsedTime;
		y+=dy* elapsedTime;
		anim.update(elapsedTime);
	}
	
	//gets sprites current x,y position
	/**
	 * @return
	 * @uml.property  name="x"
	 */
	public float getX()
	{
		return x;
	}
	/**
	 * @return
	 * @uml.property  name="y"
	 */
	public float getY()
	{
		return y;
	}
	
	//sets sprites position
	
	/**
	 * @param x
	 * @uml.property  name="x"
	 */
	public void setX(float x)
	{
		
		this.x=x;
		
	}
	
	/**
	 * @param y
	 * @uml.property  name="y"
	 */
	public void setY(float y)
	{
		this.y=y;
	}
	
	//gets sprite width height based on the size of the current image
	
	public int getWidth()
	{
		return anim.getImage().getWidth(null);
	}
	
	public int getHeight()
	{
		return anim.getImage().getHeight(null);
	}
	
	//gets vertical and horizontal velocity of the sprite in pixels per milisecs
	
	public float getVelocityX()
	{
		return dx;
	}
	
	public float getVelocityY()
	{
		return dy;
	}
	
	//Sets velocity of the sprite (pixelsXms)

	public void setVelocityX(float dx)
	{
		if (dx<0)dx=0.0001f; //no moving backward
			
		this.dx=dx;
	}
	
	public void setVelocityY(float dy)
	{
		this.dy=dy;
	}
	
	//gets the sprite current image
	
	public Image getImage()
	{
		return anim.getImage();
	}
}
